package com.taotao.druid.sqlparser.tbrouter;

import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.util.JdbcConstants;

import java.util.List;

/**
 * 给表名加后缀
 *
 * @author fanbeibei
 * @version 1.2.0
 * @date 2022/2/19 17:19
 */
public class AddTableSuffix {
    public static void main(String[] args) {


//        String content = "SELECT id, cust_company_id, label_name, enable, create_id, create_time, update_id, update_time FROM cust_company_busi_label t1\n" +
//                "        WHERE enable = 1 AND cust_company_id IN (?,?,?)";


//        String content = "UPDATE cust_company_busi_label t1\n" +
//                "        SET enable = 0,\n" +
//                "        update_id = ?,\n" +
//                "        update_time = ?\n" +
//                "        WHERE cust_company_id IN (?,?,?)";


//        String content = "INSERT INTO cust_company_busi_label(cust_company_id,\n" +
//                "            label_name,\n" +
//                "            enable,\n" +
//                "            create_id,\n" +
//                "            create_time,\n" +
//                "            update_id,\n" +
//                "            update_time)  VALUES(?,?,?,?,?,?,?)";


        String content = "DELETE FROM cust_company_busi_label WHERE cust_company_id IN (?,?,?)";

        List<SQLStatement> stmtList = SQLUtils.parseStatements(content, JdbcConstants.MYSQL);
        AddTableNameSuffixVisitorAdapter visitor = new AddTableNameSuffixVisitorAdapter("dongfeng");
        for (SQLStatement stmt : stmtList) {
            stmt.accept(visitor);
        }
        String result = SQLUtils.toSQLString(stmtList, JdbcConstants.MYSQL);
        System.out.println("---------------" + result);
    }
}
